[][src]Crate atoi

A crate for parsing integers directly form ASCII ([u8]) without encoding them into utf8 first. The name is inspired by the famous C function.

Using str::from_utf8 and str::parse is likely to be more idiomatic. Use this crate if you want to avoid decoding bytes into utf8 (e.g. for performance reasons).

Note that if you want to know how much of the input has been used, you can use the FromRadix10 trait, for example:

use atoi::FromRadix10;

/// Return the parsed integer and remaining slice if successful.
fn atoi_with_rest<I: FromRadix10>(text: &[u8]) -> ((&[u8], Option<I>)) {
    match I::from_radix_10(text) {
        (_, 0) => (text, None),
        (n, used) => (&text[used..], Some(n)),
    }
}

Enums

Sign

Representation of a numerical sign

Traits

FromRadix10

Types implementing this trait can be parsed from a positional numeral system with radix 10

FromRadix10Checked

Types implementing this trait can be parsed from a positional numeral system with radix 10. Acts much like FromRadix10, but performs additional checks for overflows.

FromRadix10Signed

Types implementing this trait can be parsed from a positional numeral system with radix 10. This trait allows for an additional sign character (+ or -) in front of the actual number in order, to allow for parsing negative values.

FromRadix10SignedChecked

Types implementing this trait can be parsed from a positional numeral system with radix 10. Acts much like FromRadix10Signed, but performs additional checks for overflows.

FromRadix16

Types implementing this trait can be parsed from a positional numeral system with radix 16

FromRadix16Checked

Types implementing this trait can be parsed from a positional numeral system with radix 16. Acts much like FromRadix16, but performs additional checks for overflows.

MaxNumDigits

A bounded integer, whose representation can overflow and therefore can only store a maximum number of digits

Functions

ascii_to_digit

Converts an ascii character to digit

atoi

Parses an integer from a slice.